package com.huawei.appmarket.service.appdetail.view.card;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.service.appdetail.bean.detail.CampaignCardItemBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailCampaignBean;
import com.huawei.hms.framework.common.ContainerUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.cii;
import o.cjk;
import o.cjm;
import o.cjo;
import o.ckt;
import o.Logger;
import o.drl;
import o.emz;
import o.CollectCheck;
import o.eqx;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class DetailCampaignCard extends drl implements OnClickListener {
    private LayoutInflater ʼ;
    private DetailCampaignBean ʽ;
    private LinearLayout ॱॱ;

    public DetailCampaignCard() {
        this.ॱ = 312;
    }

    @SuppressLint({"InflateParams"})
    public View ˊ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ʼ = layoutInflater;
        this.ˊ = layoutInflater.inflate(h.ʻॱ, null);
        azb.ˏ(this.ˊ, j.ˈʾ);
        this.ॱॱ = (LinearLayout) this.ˊ.findViewById(j.ʿˊ);
        return this.ˊ;
    }

    public boolean ˊ(List<JsonBean> list) {
        if (list == null || list.size() <= 0) {
            return false;
        }
        if (!(list.get(0) instanceof DetailCampaignBean)) {
            return false;
        }
        this.ʽ = (DetailCampaignBean) list.get(0);
        if (this.ʽ == null || CollectCheck.isEmpty(this.ʽ.ˊ())) {
            Logger.e("DetailCampaignCard", "DetailCampaignBean list is null");
            return false;
        }
        ((TextView) this.ˊ.findViewById(j.ʼﾞ)).setText(this.ʽ.ʽ());
        LinearLayout linearLayout = (LinearLayout) this.ˊ.findViewById(j.ʼꞌ);
        if (TextUtils.isEmpty(this.ʽ.ॱॱ())) {
            linearLayout.setVisibility(8);
        } else {
            linearLayout.setVisibility(0);
            linearLayout.setOnClickListener(new ckt(this));
            linearLayout.setTag(ˋ(this.ʽ.ॱॱ(), this.ʽ.ॱ()));
        }
        for (int i = 0; i < this.ʽ.ˊ().size(); i++) {
            CampaignCardItemBean campaignCardItemBean = (CampaignCardItemBean) this.ʽ.ˊ().get(i);
            ViewGroup viewGroup = (ViewGroup) this.ʼ.inflate(h.ॱˌ, null);
            azb.ˏ(viewGroup);
            ImageView imageView = (ImageView) viewGroup.findViewById(j.ʽˉ);
            TextView textView = (TextView) viewGroup.findViewById(j.ʽ);
            TextView textView2 = (TextView) viewGroup.findViewById(j.ˋ);
            TextView textView3 = (TextView) viewGroup.findViewById(j.ˆˋ);
            if (!TextUtils.isEmpty(campaignCardItemBean.ॱˌ())) {
                eqx.ˎ(imageView, campaignCardItemBean.ॱˌ());
            }
            String ꜟ = campaignCardItemBean.ꜟ();
            String ꓸ = campaignCardItemBean.ꓸ();
            String ʽ = campaignCardItemBean.ʽ();
            CharSequence ˊ = campaignCardItemBean.ˊ();
            if (TextUtils.isEmpty(ˊ)) {
                ˊ = "";
            }
            textView.setText(ˊ);
            ˊ = campaignCardItemBean.ꜞ();
            if (TextUtils.isEmpty(ˊ)) {
                ˊ = "";
            }
            textView2.setText(ˊ);
            long ˎ = ˎ(ꜟ);
            long ˎ2 = ˎ(ꓸ);
            long ˎ3 = ˎ(ʽ);
            textView.setAlpha(1.0f);
            textView2.setAlpha(1.0f);
            textView3.setAlpha(1.0f);
            String ˊ2;
            if (ˎ3 < ˎ) {
                ˊ2 = ˊ(ꜟ);
                textView3.setText(this.ˊ.getContext().getResources().getString(n.ˎͺ, new Object[]{ˊ2}));
            } else if (ˎ3 < ˎ2) {
                ˊ2 = ˊ(ꓸ);
                textView3.setText(this.ˊ.getContext().getResources().getString(n.ˋʽ, new Object[]{ˊ2}));
            } else {
                textView3.setText(this.ˊ.getContext().getResources().getString(n.ˑॱ));
                textView.setAlpha(0.3f);
                textView2.setAlpha(0.3f);
                textView3.setAlpha(0.3f);
            }
            viewGroup.setOnClickListener(new ckt(this));
            viewGroup.setTag(ˋ(campaignCardItemBean.ॱॱ(), campaignCardItemBean.ॱ()));
            viewGroup.setId(i);
            this.ॱॱ.addView(viewGroup);
        }
        return true;
    }

    private long ˎ(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        if (str == null) {
            return -1;
        }
        try {
            if (str.isEmpty()) {
                return -1;
            }
            return simpleDateFormat.parse(str).getTime();
        } catch (ParseException e) {
            Logger.e("DetailCampaignCard", e.toString());
            return -1;
        }
    }

    private String ˊ(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy/M/d", Locale.getDefault());
        if (str != null) {
            try {
                if (!str.isEmpty()) {
                    return simpleDateFormat2.format(simpleDateFormat.parse(str));
                }
            } catch (ParseException e) {
                Logger.e("DetailCampaignCard", e.toString());
                return null;
            }
        }
        return "";
    }

    public void onClick(View view) {
        String ॱॱ;
        int id = view.getId();
        if (view.getId() == j.ʼꞌ) {
            ॱॱ = this.ʽ.ॱॱ();
        } else if (id < 0 || id >= this.ʽ.ˊ().size()) {
            ॱॱ = null;
        } else {
            ॱॱ = ((CampaignCardItemBean) this.ʽ.ˊ().get(id)).ॱॱ();
        }
        if (!TextUtils.isEmpty(ॱॱ)) {
            if (ॱॱ.startsWith("html|")) {
                int indexOf = ॱॱ.indexOf(124);
                if (indexOf != -1) {
                    ॱॱ = ॱॱ.substring(indexOf + 1);
                }
                emz.ॱ(view.getContext(), "internal_webview", ॱॱ);
                return;
            }
            BaseCardBean baseCardBean = new BaseCardBean();
            baseCardBean.ॱ(ॱॱ);
            baseCardBean.ˉ(this.ʽ.ͺˏ());
            baseCardBean.ˏˎ(this.ʽ.ॱـ());
            Context context = view.getContext();
            if (!cii.ˊ().ˊ(context, baseCardBean)) {
                cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
                appDetailActivityProtocol.ˏ(new Request(baseCardBean.ॱॱ(), null));
                cjk.ˎ().ˋ(context, new cjm("appdetail.activity", appDetailActivityProtocol));
                Logger.e("DetailCampaignCard", "onClick, dispatch failed, uri = " + baseCardBean.ॱॱ());
            }
        }
    }

    private String ˋ(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return str;
        }
        if (!str.startsWith("html|") && !str.startsWith("buoy_html|")) {
            return str;
        }
        Object obj = "gSource=" + str2;
        if (str.contains(obj)) {
            return str;
        }
        String str3;
        if (str.indexOf("?") == -1) {
            str3 = str + "?";
        } else {
            str3 = str + ContainerUtils.FIELD_DELIMITER;
        }
        return str3 + obj;
    }
}
